package com.example.controller;


import com.example.pojo.PageBean;
import com.example.pojo.Supplier;
import com.example.service.impl.SupplierServiceImpl;
import com.example.tools.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 供应商
 * 商品供应商:包含供货商名、联系人、联系电话、供货商简介等。
 */
@RestController
@RequestMapping("/admin")
@Slf4j
public class SupplierController {
    @Autowired
    private SupplierServiceImpl supplierService;

    /**
     * 获取供应商信息
     *
     * @return
     */
    @PostMapping("/getSupplier")
    public Result getSupplier(
            @RequestBody Supplier supplier,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize) {

        //log.info("supplier：{}",supplier);
        PageBean pageBean = supplierService.getSupplier(supplier,page, pageSize);
        //log.info("查询全部教徒数据,deptlist:{}",pageBean);
        return Result.success(pageBean);
    }

    @GetMapping("/getSupplierList")
    public Result getGoodType() {
        List<Supplier> supplierList = supplierService.getSupplierList();
        return Result.success(supplierList);
    }

    /**
     * 修改供应商信息
     */
    @PostMapping("/changeSupplier")
    public Result changeSupplier(@RequestBody Supplier supplier) {
        supplierService.changeSupplier(supplier);
        return Result.success();
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteSupplier")
    public Result deleteSupplier(String id) {
        supplierService.deleteSupplier(id);
        return Result.success();
    }

    /**
     * 添加供应商信息
     *
     * @param supplier
     * @return
     */

    @PostMapping("/addSupplier")
    public Result addSupplier(@RequestBody Supplier supplier) {
        supplierService.addSupplier(supplier);
        return Result.success();
    }


}
